package com.srv.servlet;

import junit.framework.Assert;
import junit.framework.TestCase;

import weibo4j.http.*;
import weibo4j.*;
public class ServletNodeGetidTestCase extends TestCase {
	public ServletNodeGetidTestCase(String name){
		super(name);
	}
	//85f01aeae2a448879dc7b3bfdc26f247
	public void testInvalidArgument() { 	
		Weibo weibo = new Weibo();
		weibo.setToken("sdfsfsdf");
		
		Response response=null;
		String expect = "{\"r\":\"fail\",\"m\":\"parameter is invalid\"}";
		expect="{\"r\":\"fail\",\"m\":\"parameter is invalid\"}";
		try{
        response = weibo.client.get(TestConfig.servlet_prefix+"/travel/node/getid");        
		Assert.assertEquals(expect,response.getResponseAsString());
		
		response = weibo.client.get(TestConfig.servlet_prefix+"/travel/node/getid?c=");
		Assert.assertEquals(expect,response.getResponseAsString());
		response = weibo.client.get(TestConfig.servlet_prefix+"/travel/node/getid?c=101");
		Assert.assertEquals(expect,response.getResponseAsString());
		response = weibo.client.get(TestConfig.servlet_prefix+"/travel/node/getid?c=-11");
		Assert.assertEquals(expect,response.getResponseAsString());
		response = weibo.client.get(TestConfig.servlet_prefix+"/travel/node/getid?c=0");
		Assert.assertEquals(expect,response.getResponseAsString());
		
		expect="{\"r\":\"fail\",\"m\":\"id is invalid\"}";
		response = weibo.client.get(TestConfig.servlet_prefix+"/travel/node/getid?c=1");
		Assert.assertEquals(expect,response.getResponseAsString());		
		response = weibo.client.get(TestConfig.servlet_prefix+"/travel/node/getid?c=1&id=");
		Assert.assertEquals(expect,response.getResponseAsString());		
		response = weibo.client.get(TestConfig.servlet_prefix+"/travel/node/getid?c=1&id=sdfsdf");
		Assert.assertEquals(expect,response.getResponseAsString());
		response = weibo.client.get(TestConfig.servlet_prefix+"/travel/node/getid?c=1&id=85f01aeae2a448879dc7b3bfdc26f247s");
		Assert.assertEquals(expect,response.getResponseAsString());
		
		}catch(Exception e){
			e.printStackTrace();
		}		
    }
	//85f01aeae2a448879dc7b3bfdc26f247
	public void testValidArgument() { 	
		Weibo weibo = new Weibo();
		weibo.setToken("sdfsfsdf");
		
		Response response=null;
		String expect = "{\"r\":\"ok\",\"m\":[\"15aa464160d74fe8b735096bcc31dd77\",\"15aa464160d74fe8b735096bcc31dd77\"]}";		
		try{
        response = weibo.client.get(TestConfig.servlet_prefix+"/travel/node/getid?c=2&id=85f01aeae2a448879dc7b3bfdc26f247");  
		Assert.assertEquals(expect.length(),response.getResponseAsString().length());		
		}catch(Exception e){
			e.printStackTrace();
		}		
    }
}
